package cn.iocoder.yudao.module.movie.controller.app;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.movie.api.domain.CityDO;
import cn.iocoder.yudao.module.movie.api.domain.MovieCinemasDO;
import cn.iocoder.yudao.module.movie.api.domain.MovieListDO;
import cn.iocoder.yudao.module.movie.api.params.MovieCinemaParamDO;
import cn.iocoder.yudao.module.movie.controller.app.convert.MovieRespVOConvert;
import cn.iocoder.yudao.module.movie.controller.app.vo.AppCityRespVO;
import cn.iocoder.yudao.module.movie.controller.app.vo.AppMovieCinemaParamVO;
import cn.iocoder.yudao.module.movie.controller.app.vo.AppMovieCinemaVO;
import cn.iocoder.yudao.module.movie.controller.app.vo.AppMoviesRespVO;
import cn.iocoder.yudao.module.movie.serive.movie.MovieService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import java.util.List;
import java.util.stream.Collectors;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

/**
 * <p>  </p>
 */
@Tag(name = "电影 APP - 电影信息")
@RestController
@RequestMapping("/movie")
@Validated
public class AppMoviesController {
    @Resource
    private MovieService movieService;


    @GetMapping("/city-list")
    @Operation(summary = "获得城市列表")
    public CommonResult<List<AppCityRespVO>> getCityList() {
        List<CityDO> cityList = movieService.getCityList();
        return success(cityList.stream().map(MovieRespVOConvert::convert).collect(Collectors.toList()));
    }

    @GetMapping("/hot-list")
    @Operation(summary = "获得热映电影")
    @Parameter(name = "cityId", description = "城市id", required = true)
    public CommonResult<AppMoviesRespVO> getHotList(@RequestParam("cityId") String cityId) {
        MovieListDO movieListDO = movieService.getHotList(cityId);
        return success(MovieRespVOConvert.convert(movieListDO));
    }

    @GetMapping("/coming-list")
    @Operation(summary = "获取即将上映电影")
    @Parameter(name = "cityId", description = "城市id", required = true)
    public CommonResult<AppMoviesRespVO> getComingList(@RequestParam("cityId") String cityId) {
        MovieListDO movieListDO = movieService.getComingList(cityId);
        return success(MovieRespVOConvert.convert(movieListDO));
    }

    @PostMapping("/movie-cinemas")
    @Operation(summary = "获取电影影院列表")
    public CommonResult<AppMovieCinemaVO> getMovieCinemas(@RequestBody AppMovieCinemaParamVO movieCinemaParamVO) {
        MovieCinemasDO movieCinemas = movieService.getMovieCinemas(BeanUtils.toBean(movieCinemaParamVO, MovieCinemaParamDO.class));
        return success(MovieRespVOConvert.convert(movieCinemas));
    }

}
